package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysMessageSendRecordDetailsQuery;
import com.jcfk.system.domain.dto.SysMessageSendRecordDetailsDTO;
import com.jcfk.system.service.SysMessageSendRecordDetailsService;
import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 消息发送记录
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2023-12-29
 */
@Api(tags = {"消息发送记录管理"})
@RestController
@RequestMapping("sysmessagesendrecorddetails")
public class SysMessageSendRecordDetailsController {
    @Autowired
    private SysMessageSendRecordDetailsService sysMessageSendRecordDetailsService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysMessageSendRecordDetailsQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询消息发送记录")
    @PostMapping("/queryByPage")
    @ResponseBody
    public RetPage<SysMessageSendRecordDetailsDTO> queryByPage(@RequestBody ReqPageParam<SysMessageSendRecordDetailsQuery> requestParam) {
        DataPage<SysMessageSendRecordDetailsDTO> page = new DataPage<SysMessageSendRecordDetailsDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysMessageSendRecordDetailsDTO.class);
        page = sysMessageSendRecordDetailsService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  消息发送记录
     * 根据id 查询详情
     */
    @ApiOperation("查询消息发送记录")
    @GetMapping("/get/{id}")
    @ResponseBody
    public RetResult<SysMessageSendRecordDetailsDTO> get(@PathVariable("id") String id) {
            SysMessageSendRecordDetailsDTO item = sysMessageSendRecordDetailsService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理消息发送记录
     */
    @ApiOperation("保存消息发送记录")
    @PostMapping("/save")
    @ResponseBody
    @RequestLogHeader(modular = "消息发送记录管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysMessageSendRecordDetailsDTO sysMessageSendRecordDetails) {
        // 数据校验
        RetResult ret = sysMessageSendRecordDetailsService.isValid(sysMessageSendRecordDetails);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysMessageSendRecordDetails.getId())){
            // 新增
            sysMessageSendRecordDetailsService.insert(sysMessageSendRecordDetails);
        } else{
            // 更新
            sysMessageSendRecordDetailsService.update(sysMessageSendRecordDetails);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除消息发送记录
     */
    @ApiOperation("批量删除消息发送记录")
    @ResponseBody
    @PostMapping("/delete")
    @RequestLogHeader(modular = "消息发送记录管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysMessageSendRecordDetailsDTO sysMessageSendRecordDetails) {
        return RetResult.ok(sysMessageSendRecordDetailsService.removeBigBatch(sysMessageSendRecordDetails.getIds()));
    }



}
